package com.wodwl.configuration;
import org.apache.commons.mail.EmailException;     
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;  
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.MultiPartEmail;

    
public class Test      
{     
    public Test()     
    {     
             
    }     
         
    public static void main(String[] args)     
    {     
       // sendText(); 
        sendHtml();
        System.out.println("ok");
    }     
    //发送普通邮件  
    public static void sendText()     
    {     
        SimpleEmail email = new SimpleEmail();        
        email.setTLS(true);             
        email.setHostName("smtp.gmail.com");           
        email.setAuthentication("k6k4abc@gmail.com", "=1-203abc");   //用户名和密码     
             
        try      
        {     
            email.addTo("wo_dwl@163.com"); //接收方     
            email.setFrom("k6k4abc@gmail.com");       //发送方       
            email.setSubject("Java Mail Test");         //标题        
            email.setMsg("Just a simple send test .");   //内容        
            email.send();      
                 
        } catch (EmailException e) {     
            e.printStackTrace();     
        }      
    } 
  //发送普通邮件  
    public static void sendHtml()     
    {     
        HtmlEmail email = new HtmlEmail();        
        email.setTLS(true);             
        email.setHostName("smtp.gmail.com");           
        email.setAuthentication("k6k4abc@gmail.com", "=1-203abc");   //用户名和密码     
             
        try      
        {     
            email.addTo("wo_dwl@163.com"); //接收方     
            email.setFrom("k6k4abc@gmail.com");       //发送方       
            email.setSubject("Java Mail Test");         //标题        
            email.setHtmlMsg("Just a simple send test .<a href=\"http://baidu.com\">baidu</a>");   //内容        
            email.send();      
                 
        } catch (EmailException e) {     
            e.printStackTrace();     
        }      
    } 
    //发送带附件的邮件
    public static void sendAttachment(){
    	//创建一个Email附件
        EmailAttachment emailAttachment = new EmailAttachment();
        emailAttachment.setPath("F:/资料/实验室人事项目/图片/logo.png");
        //emailAttachment.setURL(new URL("http://www.blogjava.net/bulktree/picture/bulktree.jpg"));
        emailAttachment.setDisposition(EmailAttachment.ATTACHMENT);
        emailAttachment.setDescription("This is Smile picture");
        //emailAttachment.setName("bulktree");//若不设置该方法将使用原文件名称
        // 创建一个email
        MultiPartEmail multipartemail = new MultiPartEmail();
        multipartemail.setTLS(true);
        multipartemail.setHostName("smtp.gmail.com");
        multipartemail.setAuthentication("k6k4abc@gmail.com", "=1-203abc");
       
        try {
			multipartemail.addTo("wo_dwl@163.com", "username");
			multipartemail.setFrom("k6k4abc@gmail.com", "工作室");
		    multipartemail.setSubject("This is a attachment Email");
		    multipartemail.setMsg("this a attachment Eamil Test");
		    multipartemail.attach(emailAttachment); //添加附件
		    multipartemail.send(); //发送邮件
		} catch (EmailException e) {
			e.printStackTrace();
		}
    }
    
}   




